package com.netty.protobuf.client;

//import com.netty.protobuf.MyDataInfo;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.util.Random;

/**
 * Created by Administrator on 2018/11/1/001.
 */
public class TestClientHandler extends SimpleChannelInboundHandler<Object> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {

    }

    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        System.out.println("...");
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        int randomInt = new Random().nextInt(3);
//        MyDataInfo.Message mesage = null;
//        if (randomInt == 0) {
//            MyDataInfo.Person p = MyDataInfo.Person.newBuilder().setName("张三").setEmail("63534.@qq.com").setId(123).build();
//            mesage = MyDataInfo.Message.newBuilder().setDataType(MyDataInfo.Message.DataType.PersonType).setPerson(p).build();
//        }
//        if (randomInt == 1) {
//            MyDataInfo.Cat cat = MyDataInfo.Cat.newBuilder().setName("Dog..").setCity("bj").build();
//            mesage = MyDataInfo.Message.newBuilder().setDataType(MyDataInfo.Message.DataType.CatType).setCat(cat).build();
//        }
//        if (randomInt == 2) {
//            MyDataInfo.Dog dog = MyDataInfo.Dog.newBuilder().setName("Cat..").setAge("123").build();
//            mesage = MyDataInfo.Message.newBuilder().setDataType(MyDataInfo.Message.DataType.DogType).setDog(dog).build();
//        }
//        ctx.channel().writeAndFlush(mesage);
    }
}
